
#include <openssl/aes.h>
#include <openssl/bio.h>
#include <openssl/blowfish.h>
#include <openssl/des.h>
#include <openssl/idea.h>
#include <string>
#include <atomic>

#include "filter.hpp"
#include "crypto.h"

crypto::crypto( io_type t , filterList * l )
: filterIO( t , l )
{
    //ctor
}

crypto::~crypto()
{
    //dtor
}

bool crypto::on_forward( size_t len , const char * data , err_code &err , size_t& rlen , char ** rd )
{
	bool ret = false;
	if( data == nullptr ) return false;
	if( len == 0 ) return false;

	switch( m_mtd ){
	case AES:
		ret = en_aes( len , data , rlen , rd );
		break;
	case DES:
		ret = en_des( len , data , rlen , rd );
		break;
	case IDEA:
		ret = en_idea( len , data , rlen , rd );
		break;
	case BF:
	default:
		ret = en_bf( len , data , rlen , rd );
		break;
	case SIGNAL:
		ret = en_signal( len , data , rlen , rd );
		break;
	}
    return ret;
}

bool crypto::on_backward( size_t len , const char * data , err_code &err , size_t& rlen , char ** rd  )
{
	bool ret = false;
	if( data == nullptr ) return false;
	if( len == 0 ) return false;

	switch( m_mtd ){
	case AES:
		ret = de_aes( len , data , rlen , rd );
		break;
	case DES:
		ret = de_des( len , data , rlen , rd );
		break;
	case IDEA:
		ret = de_idea( len , data , rlen , rd );
		break;
	case BF:
	default:
		ret = de_bf( len , data , rlen , rd );
		break;
	case SIGNAL:
		ret = de_signal( len , data , rlen , rd );
		break;
	}
	return ret;
}

bool crypto :: en_aes( size_t len , const char * data , size_t& rlen , char ** rd )
{
	bool  ret = false;

	return ret;
}
bool crypto :: en_des( size_t len , const char * data , size_t& rlen , char ** rd )
{
	bool  ret = false;

	return ret;
}
bool crypto :: en_idea( size_t len , const char * data , size_t& rlen , char ** rd )
{
	bool  ret = false;

	return ret;
}
bool crypto :: en_bf( size_t len , const char * data , size_t& rlen , char ** rd )
{
	bool  ret = false;

	return ret;
}
bool crypto :: en_signal( size_t len , const char * data , size_t& rlen , char ** rd )
{
	bool  ret = false;

	return ret;
}
bool crypto :: de_aes( size_t len , const char * data , size_t& rlen , char ** rd )
{
	bool  ret = false;

	return ret;
}
bool crypto :: de_des( size_t len , const char * data , size_t& rlen , char ** rd )
{
	bool  ret = false;

	return ret;
}
bool crypto :: de_idea( size_t len , const char * data , size_t& rlen , char ** rd )
{
	bool  ret = false;

	return ret;
}
bool crypto :: de_bf( size_t len , const char * data , size_t& rlen , char ** rd )
{
	bool  ret = false;

	return ret;
}
bool crypto :: de_signal( size_t len , const char * data , size_t& rlen , char ** rd )
{
	bool  ret = false;

	return ret;
}
